<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="styles.css">
    <title>美女聚集</title>
</head>

<body>
    <!-- 右上角笑脸刷新页面 -->
    <div class="emoji-wrapper">
        &#x1F60D;
    </div>

    <!-- 搜索框 -->
    <div class="search-bar">
        <form action="#">
            <input type="text" placeholder="搜索...">
            <button type="submit">搜索</button>
        </form>
    </div>
    <!-- 顶部导航 -->
    <header>
        <nav class="top-navigation">
            <ul>
                <li><a href="#">通知</a></li>
                <li><a href="#">私信</a></li>
                <div class="dropdown">
                    <button class="dropbtn" id="submitBtn">投稿</button>
                    <div class="dropdown-content" id="myDropdown">
                        <a href="#">发布视频</a>
                        <a href="#">视频管理</a>
                        <a href="#">创作中心</a>
                    </div>
                </div>
                <button id="toggleAuthBox" onclick="showLoginBox()">登录/注册</button>
            </ul>
        </nav>
    </header>

    <!-- 侧栏导航 -->
    <aside class="sidebar-navigation">
        <ul>
            <li><a href="#">产品1</a></li>
            <li><a href="#">产品2</a></li>
            <li><a href="#">产品3</a></li>
            <li><a href="#">常见问题</a></li>
        </ul>
    </aside>

    <!-- 主内容区域 -->
    <main>
        <h1>欢迎来到我们的网站</h1>
        <p>这里是主要内容...</p>
    </main>


    <!-- 登录表单 -->
    <div class="login-box">
        <span class="close-btn" onclick="closeLoginOrRegisterBox()">×</span>
        <h2>登录</h2>
        <form action="login.php" method="post">
            <input type="text" placeholder="用户名" required>
            <input type="password" placeholder="密码" required>
            <button type="submit">登录</button>
            <br><br>
            <a href="#" onclick="showRegisterBox(); return false;">没有账号？去注册</a>
        </form>
    </div>

    <!-- 注册表单 -->
    <div class="register-box" style="display: none;">
        <span class="close-btn" onclick="closeLoginOrRegisterBox()">×</span>
        <h2>注册</h2>
        <form id="register-form">
            <input type="text" id="regUsername" placeholder="用户名" required>
            <input type="password" id="regPassword" placeholder="密码" required>
            <input type="password" id="confirmPassword" placeholder="再次输入密码" required>
            <button type="submit">注册</button>
            <br><br>
            <a href="#" onclick="showLoginBox(); return false;">已有账号？去登录</a>
        </form>
    </div>
    <script>
        document.getElementById('register-form').addEventListener('submit', function(event) {
            event.preventDefault(); // 阻止默认的表单提交
        
            const username = document.getElementById('regUsername').value.trim();
            const password = document.getElementById('regPassword').value;
            const confirmPassword = document.getElementById('confirmPassword').value;
        
            if (username === '') {
                alert('用户名不能为空');
                return;
            }
        
            if (password !== confirmPassword) {
                alert('两次输入的密码不一致');
                return;
            }
        
            const formData = new FormData(this);
            formData.set('regUsername', username);
        
            fetch('register.php', {
                method: 'POST',
                body: formData
            })
            .then(response => {
                console.log('服务器响应:', response.text()); // 读取并保存响应体
                return response.text();
            })
            .then(data => {
                console.log('服务器响应数据:', data);
                if (data !== '用户注册成功') {
                    alert(data); // 显示服务器返回的错误信息
                } else {
                    alert('注册成功');
                    // 这里可以添加成功注册后的操作，如跳转到登录页面
                }
            })
            .catch(error => {
                console.error('注册失败:', error);
                alert('注册失败，请稍后再试');
            });
        });
        </script>


    <script src="scripts.js"></script>